package com.fsx.servertokenlogin.handler;

import com.fsx.servertokenlogin.dto.LoginResult;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.MalformedJwtException;
import io.jsonwebtoken.SignatureException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class LoginExceptionHandler {

    @ExceptionHandler(value = ExpiredJwtException.class)
    public LoginResult<String> expiredJwtException(ExpiredJwtException e){
        return new LoginResult<>(-1, "token过期");
    }
    @ExceptionHandler(value = SignatureException.class)
    public LoginResult<String> signatureException(SignatureException e){
        return new LoginResult<>(-1, "签名有误");
    }
    @ExceptionHandler(value = MalformedJwtException.class)
    public LoginResult<String> malformedJwtException(MalformedJwtException e){
        return new LoginResult<>(-1, "密钥验证不一致");
    }

    @ExceptionHandler(value = JwtException.class)
    public LoginResult<String> jwtException(JwtException e) {
        return new LoginResult<>(-1, e.getMessage());
    }
    @ExceptionHandler(value = RuntimeException.class)
    public LoginResult<String> runtimeException(RuntimeException e){
        return new LoginResult<>(-1, e.getMessage());
    }
//    @ExceptionHandler(value = Exception.class)
//    public LoginResult<String> exceptionHandler(Exception e) {
//        return new LoginResult<>(-1, "系统出了点问题,请稍后再试");
//    }
}
